// pages/index/index.ts
Page({
  data: {
    travelRecords: [] as any[],
    loading: true,
  },

  onLoad() {
    this.loadTravelRecords();
  },

  onShow() {
    this.loadTravelRecords();
  },

  async loadTravelRecords() {
    try {
      this.setData({ loading: true });
      // 这里需要导入 api.ts，但由于微信小程序限制，我们先模拟数据
      const mockData = [
        {
          id: 1,
          title: '北京之旅',
          location: '北京',
          date: '2024-01-15',
          images: [],
          comments_count: 5,
          likes_count: 12,
        },
        {
          id: 2,
          title: '上海之行',
          location: '上海',
          date: '2024-02-20',
          images: [],
          comments_count: 3,
          likes_count: 8,
        },
      ];
      
      this.setData({
        travelRecords: mockData,
        loading: false,
      });
    } catch (error) {
      console.error('加载旅游记录失败:', error);
      this.setData({ loading: false });
      wx.showToast({
        title: '加载失败',
        icon: 'none',
      });
    }
  },

  navigateToDetail(e: any) {
    const id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/travel/detail/index?id=${id}`,
    });
  },

  navigateToCreate() {
    wx.navigateTo({
      url: '/pages/travel/create/index',
    });
  },

  navigateToList() {
    wx.switchTab({
      url: '/pages/travel/list/index',
    });
  },
});
